﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Collections.ObjectModel;
using MvcApplication6.DAL.Helper;
using MvcApplication6.Models;


namespace MvcApplication6.DAL
{
    public class MenuL1DAL
    {
        //---------------------Menu_l1SearchById-----------------------------
        public MenuL1Model Menu_l1SearchById(int id)
        {
            MenuL1Model obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));


            SqlDataReader dr = SQLHelper.ExecuteReader("spMenu_l1SearchById", parameterList);
            while (dr.Read())
            {
                obj = new MenuL1Model();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Position = int.Parse(dr["position"].ToString());
            }
            dr.Close();

            return obj;
        }

        //---------------------Menu_l1Select-----------------------------
        public List<MenuL1Model> Menu_l1Select()
        {

            List<MenuL1Model> lst = new List<MenuL1Model>();

            MenuL1Model obj = null;


            SqlDataReader dr = SQLHelper.ExecuteReader("spMenu_l1Search");
            while (dr.Read())
            {
                obj = new MenuL1Model();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Position = int.Parse(dr["position"].ToString());

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }


        //---------------------Menu_l1Insert-----------------------------
        public int Menu_l1Insert(string name, int position)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@position", position));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l1Insert", parameterList);

            return i;
        }

        //---------------------Menu_l1Update-----------------------------
        public int Menu_l1Update(int id, string name, int position)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@position", position));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l1Update", parameterList);

            return i;
        }

        //---------------------Menu_l1Delete-----------------------------
        public int Menu_l1Delete(int id)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l1Delete", parameterList);

            return i;
        }
    }
}